//base
import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
//less
import './index.less'
import { navigateTo } from '../../../../crossplatform/apiservice/navigate'
import pagejumplist from '../../../../configuration/pagejumplist.json'
import { showToast } from '../../../../crossplatform/apiservice/toast'
import ListItem from '../../../../components/page-components/list-item'

class JobPost extends Component {
  constructor(props) {
    super(props)
    this.state = {
      infoList: [
        {
          name: '兼职岗位',
          icon: 'https://imagesize.hrwork.com/sp/files/1de1d034-adc2-4dfd-9282-321b80ed36b8.png',
          desc: '去发布'
        },
        {
          name: '实习岗位',
          icon: 'https://imagesize.hrwork.com/sp/files/7a606298-57f8-4ba8-a5f3-37579c22c0ed.png',
          desc: '去发布'
        },
        {
          name: '全职岗位',
          icon: 'https://imagesize.hrwork.com/sp/files/11f07c11-97a3-4417-b016-f2440f46d0f4.png',
          desc: '去发布'
        }
      ]
    }
  }

  componentWillMount() {
    //onLoad
  }

  componentDidMount() {
    //onready
  }

  componentDidShow() {
    // onshow
  }

  componentWillUnmount() {
    //onUnload
  }

  componentWillReceiveProps(nextprops) {}

  onJumpTo = name => {
    // 跳转页面
    const { companyId } = this.props
    if (companyId) {
      switch (name) {
        case '兼职岗位':
          navigateTo({
            url: `${pagejumplist['manage-jobs'].path}?pagetype=parttime`
          })
          break
        case '实习岗位':
          navigateTo({
            url: `${pagejumplist['manage-jobs'].path}?pagetype=practime`
          })
          break
        case '全职岗位':
          navigateTo({
            url: `${pagejumplist['manage-jobs'].path}?pagetype=fulltime`
          })
          break
      }
    } else if (zhichuUserIdB) {
      showToast({
        title: '您还没有归属的公司哦～'
      })
    }
  }

  render() {
    const { infoList } = this.state
    const { postData } = this.props
    return (
      <View className="JobPost_id13251">
        {/* <View className="image-wrap" onClick={this.gotoPostjob}>
          <Image
            className="left-image"
            src="https://imagesize.hrwork.com/sp/files/4d231065-293c-47fa-9538-23afaf6e6dc4.png"
          />
          <View className="view-text">职位发布</View>
        </View> */}

        <View className="title">职位管理</View>

        <View className="list">
          {infoList.map((item, index) => {
            let desc = ''
            switch(index) {
              case 0:
              desc = postData && postData.partAll ? `${postData.partOnline}/${postData.partAll}` : ''
              break
              case 1:
              desc = postData && postData.internshipAll ? `${postData.internshipOnline}/${postData.internshipAll}` : ''
              break
              case 2:
              desc = postData && postData.fullAll ? `${postData.fullOnline}/${postData.fullAll}` : ''
              break
            }
            return (
              <ListItem
                key={index}
                name={item.name}
                num={item.num}
                icon={item.icon}
                desc={desc || item.desc}
                userId={this.props.userId}
                onJumpTo={this.onJumpTo}
              />
            )
          })}
        </View>
      </View>
    )
  }
}

export default JobPost
